home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TeX 1995 July
/
TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO
/
web
/
spiderweb
/
tools
/
excerpt
/
section.c
< prev
Wrap
C/C++ Source or Header
|
1991-01-14
|
2KB
|
71 lines
#include <stdio.h>
main() {
FILE * ttyin, *ttyout;
char buffer[800];
char ttybuffer[80];
int line;
int level,skiplevel;
int skipping=0;
int all=0;
char *name = buffer;
#define barf fprintf(stderr,"section: file error\n"); exit(1);
if (NULL==(ttyin=fopen("/dev/tty","r"))) {
barf;
}
if (NULL==(ttyout=fopen("/dev/tty","w"))) {
barf;
}
printf("1 ");
level=skiplevel=99;
while (gets(buffer)!=NULL) {
sscanf(buffer,"%d", &line);
if (gets(buffer)==NULL) {barf;}
sscanf(buffer,"%d", &level);
if (gets(buffer)==NULL) {barf;}
/* fprintf(ttyout,"Checking level %d section on line %4d \"%s\"\n",
/* level, line, name);
/* fprintf(ttyout,"skipping=%d and skiplevel=%d\n", skipping,skiplevel);
*/
if ((!skipping) || level <= skiplevel) {
if (all && level>skiplevel) {
fprintf(ttyout," includes \"%s\"...\n", name);
} else {
int querycount=0;
skiplevel=level;
*ttybuffer='X';
while (*ttybuffer !='y' && *ttybuffer != 'n' && *ttybuffer != 'a'
&& *ttybuffer != '\0') {
fprintf(ttyout,"Print level %d section \"%s\" [ayn]? ",
level, name);
fflush(ttyout);
fgets(ttybuffer,80,ttyin);
if (++querycount>10) {
fprintf(ttyout,
"If you won't type 'y', 'n', 'a', or <CR>, I'll just quit\n");
exit(8);
}
}
if (*ttybuffer=='n') {
if (!skipping) printf ("%d ", -line);
skipping = 1;
all = 0;
} else if (*ttybuffer=='a' || *ttybuffer=='\0') {
if (skipping) printf ("%d ", line);
skipping = 0;
all=1;
} else {
if (skipping) printf ("%d ", line);
skipping = 0;
all=0;
}
}
}
}
}